#ifndef __DEF_DETAILDIALOG_H__
#define __DEF_DETAILDIALOG_H__

#include <wx/wx.h>
#include <wx/notebook.h>
#include <wx/datectrl.h>
#include <wx/bmpcbox.h>
#include <wx/spinctrl.h>
#include "appconstant.h"

#include <vector>
#include <stack>

class DetailEditor: public wxDialog
{
public:
	DetailEditor(wxWindow *parent);
	~DetailEditor(void) {};
	
	void bindData_InputDate(wxDateTime dt);
	void bindData_ExistData(DB_day db);
	wxDateTime GetDataDate(void)
	{
		return de_InputDate->GetValue();
	}
	int GetDataInputType(void)
	{
		return de_InputType->GetSelection();
	}
	int GetDataIncome(void)
	{
		return de_IncomeType->GetSelection();
	}
	int GetDataExpense(void)
	{
		return dbexpenseId.at(de_ExpenseList->GetSelection());
	}
	wxString GetDataExpenseString(void)
	{
		return de_ExpenseList->GetStringSelection();
	}
	int GetDataItems(void)
	{
		if (de_ItemsList->GetSelection() >= 0) {
			return dbitemsId.at(de_ItemsList->GetSelection());
		}else{
			return -1;
		}
	}
	wxString GetDataItemsString(void)
	{
		return de_ItemsList->GetStringSelection();
	}
	int GetDataHandling(void)
	{
		return dbaccountId.at(de_InAccounts->GetSelection());
	}
	wxString GetDataHandlingString(void)
	{
		return de_InAccounts->GetStringSelection();
	}
	int GetDataValue(void)
	{
		long tmp;
		de_CalcLine->GetValue().ToLong(&tmp);
		return (int)tmp;
	}
	wxString GetDataMemo(void)
	{
		return de_MemoBox->GetValue();
	}
	void SetExpense(InoutType io);
	void SetItems(int expenseId);
	void SetAccount(int handle);
	void ChangeEnable(int type, bool flag = true);
	void ClearControl(void);
protected:
	wxDatePickerCtrl *de_InputDate;
	wxRadioBox *de_InputType;
	wxRadioBox *de_IncomeType;
	wxPanel *detailPanel;
		wxNotebook *de_SettingList;
			wxPanel *de_ExpensePanel;
				wxBitmapComboBox *de_ExpenseList;
				wxBitmapComboBox *de_ItemsList;
				wxChoice *de_InAccounts;
				wxChoice *de_OutAccounts;
			wxPanel *de_CalcPanel;
				wxTextCtrl *de_CalcLine;
				wxButton *de_CalcNumBtn[11];
				wxButton *de_CalcFuncBtn[4];
				wxButton *de_CalcEnterBtn;
				wxButton *de_CalcClearBtn;
				wxSpinCtrl *de_CalcTax;
				wxButton *de_CalcClearTax;
				wxButton *de_CalcIncludeTax;
				wxStaticText *de_CalcExplain;
			wxTextCtrl *de_MemoBox;
	wxButton *de_OkBtn;
	wxButton *de_CanBtn;
	
	void de_OkBtn_clicked(wxCommandEvent &event);
	void de_CanBtn_clicked(wxCommandEvent &event);
	void de_CalcNumBtn_clicked(wxCommandEvent &event);
	void de_CalcFuncBtn_clicked(wxCommandEvent &event);
	void de_CalcEnterBtn_clicked(wxCommandEvent &event);
	void de_CalcClearBtn_clicked(wxCommandEvent &event);
	void de_CalcClearTax_clicked(wxCommandEvent &event);
	void de_CalcIncludeTax_clicked(wxCommandEvent &event);
	void de_CalcTax_scrolled(wxScrollEvent &event);
	void de_IncomeType_selected(wxCommandEvent &event);
	void de_ExpenseList_selected(wxCommandEvent &event);
	void de_InputType_changed(wxCommandEvent &event);
	void de_SettingList_changed(wxNotebookEvent &event);
private:
	DECLARE_EVENT_TABLE()

	wxPanel *setup_expensepage(wxNotebook *book);
	wxPanel *setup_calcpage(wxNotebook *book);
	
	std::stack <int> expr;
	std::stack <int> expr_oper;
	bool push_oper;
	bool push_enter;
	long savevalue;
	int saveoper;
	int calc_expressionStack(unsigned int e1, unsigned int e2, int op);
	void addTax(int pos);
	std::vector<int> dbexpenseId;
	std::vector<int> dbitemsId;
	std::vector<int> dbaccountId;
	bool editmode;
	int oldexpense, olditems;
};

enum {
	detaile_ok = 50,
	detaile_can,
	detaile_num0,
	detaile_num1,
	detaile_num2,
	detaile_num3,
	detaile_num4,
	detaile_num5,
	detaile_num6,
	detaile_num7,
	detaile_num8,
	detaile_num9,
	detaile_num00,
	detaile_add,
	detaile_sub,
	detaile_multi,
	detaile_div,
	detaile_enter,
	detaile_clear,
	detaile_tax,
	detaile_cleartax,
	detaile_includetax,
	detaile_iobox,
	detaile_expenselist,
	detaile_input,
	detaile_handle,
	detaile_setlist
};

#endif